namespace TamTam.SharePoint.CruiseControl {

    using System;
    using System.Collections;
    using ThoughtWorks.CruiseControl.Remote;

    public class GenericSort : IComparer
    {
        public GenericSort(string sortMethodName, string sortOrder)
        {
            this.sortMethodName = sortMethodName;
            this.sortOrder = sortOrder;
        }

        public int Compare(object x, object y)
        {
            ProjectStatus status1 = x as ProjectStatus;
            ProjectStatus status2 = y as ProjectStatus;
            IComparable comparable1 = (IComparable) typeof(ProjectStatus).GetProperty(this.sortMethodName).GetValue(status1, null);
            IComparable comparable2 = (IComparable) typeof(ProjectStatus).GetProperty(this.sortMethodName).GetValue(status2, null);
            if ((this.sortOrder != null) && this.sortOrder.ToUpper().Equals("ASC"))
            {
                return comparable1.CompareTo(comparable2);
            }
            return comparable2.CompareTo(comparable1);
        }


        private string sortMethodName;
        private string sortOrder;
    }
}

